package com.qt.collection.myset;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class CollectionsDemo02 {

    public static void main(String[] args) {
        /**
         *
          */
        /*
        //1.定义集合
        ArrayList<String> list = new ArrayList<>();
        //2.添加数据
        Collections.addAll(list,"范闲","范建","范统","杜子腾","杜琦燕","宋合泛","侯笼藤","朱益群","朱穆朗玛峰","袁明媛");
        //3.点名
        Random random = new Random();
        int index = random.nextInt(list.size());
        System.out.println(list.get(index));

        Collections.shuffle(list);
        System.out.println(list.get(0));*/
        System.out.println("---------------------");


        ArrayList<Integer> indexList = new ArrayList<>();
        Collections.addAll(indexList,1,1,1,1,1,1,1,0,0,0);
        Collections.shuffle(indexList);
        Random random1 = new Random();



        ArrayList<String> boyList = new ArrayList<>();
        ArrayList<String> boyList2 = new ArrayList<>();
        ArrayList<String> girlList = new ArrayList<>();
        ArrayList<String> girlList2 = new ArrayList<>();
        Collections.addAll(boyList,"范闲","范建","范统","杜子腾","杜琦燕");
        Collections.addAll(girlList,"曲丽丽","林东东","吴加好");
        int resSize = boyList.size() + girlList.size();


        for (int i = 0; i < 10; i++) {
            System.out.println("第" + i + "轮开始了");
            for (int j = 0; j < resSize; j++) {
                int res = indexList.get(random1.nextInt(indexList.size()));
                //如果男生点完，就点女生，反之亦如此
                //被点过的不能再点
                //如果点完了就开始下一轮
                if(res == 1){
                    String name;
                    if(boyList.size() > 0){
                        int boyIndex = random1.nextInt(boyList.size());
                        name = boyList.remove(boyIndex);
                        boyList2.add(name);
                    }else {
                        int girlIndex = random1.nextInt(girlList.size());
                        name = girlList.remove(girlIndex);
                        girlList2.add(name);
                    }
                    System.out.println(name);
                }else if(res == 0 ) {
                    String name;
                    if(girlList.size() > 0){
                        int girlIndex = random1.nextInt(girlList.size());
                        name = girlList.remove(girlIndex);
                        girlList2.add(name);
                    }else {
                        int boyIndex = random1.nextInt(boyList.size());
                        name = boyList.remove(boyIndex);
                        boyList2.add(name);
                    }
                    System.out.println(name);
                }
            }

            //Collections.copy(boyList2,boyList);
            //Collections.copy(girlList2,girlList);
            boyList.addAll(boyList2);
            girlList.addAll(girlList2);
            boyList2.clear();
            girlList2.clear();

        }







    }



}
